<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>ajax</title>
    </head>
    <body>

        <script>
            function ajax(url){
                return new Promise((resolve,reject)=>{
                   let xhr = new XMLHttpRequest()
                   xhr.open('get',url)
                   xhr.send()
                   xhr.onreadystatechange = function(res){
                    if(xhr.readyState == 4){
                        console.log(xhr)
                        console.log(res)
                        if(xhr.status >= 200 && xhr.status < 300){
                            let res = JSON.parse(xhr.responseText)
                            resolve(res)
                        }else{
                            reject(xhr.responseText)
                        }
                    }
                   }
                })
            }

            ajax('./1.json')
            .then((res)=>{
                console.log(res)
                return ajax('./2.json')
            })
            .then((res)=>{
                //fulfilled/rejected，本身返回promise对象
                console.log(res)
            })
            .then(()=>{
                //pending->fukfilled，自动包装成promise返回
                return 1
            })
            .catch((err)=>{
                console.log(err)
            })
            
        </script>
    </body>
</html>